package com.hhsjdesign.dynamicui.core.property.viewdata

import android.graphics.Color
import com.hhsjdesign.dynamicui.annoprocess.AWidgetItemData
import com.hhsjdesign.dynamicui.core.property.ViewBaseProperty
import com.hhsjdesign.dynamicui.core.property.item.ImageViewProperty
import com.hhsjdesign.dynamicui.core.property.item.TextViewProperty
import com.hhsjdesign.dynamicui.utils.ItemViewTypeConst
import com.hhsjdesign.dynamicui.utils.ViewFunCode
import com.hhsjdesign.dynamicui.utils.designUnit2px
import com.hhsjdesign.dynamicui.utils.makeTag
import org.json.JSONObject

@AWidgetItemData(ItemViewTypeConst.SERVICE_MENU_1ROW_1COR)
class DefaultTabItemViewData constructor(val itemViewType: String, jo: JSONObject) : ItemViewData() {
    /**
     * 有 左icon，左title，右desc，右icon，背景
     */
    init {
        type = ITEM_VIEW_TYPE_FRAME
        property = ViewBaseProperty()
        treeList = ArrayList<ItemViewData>().apply {
            //背景图
            add(ItemViewData().apply {
                type = ITEM_VIEW_TYPE_VIEW
                viewTag = makeTag(ViewFunCode.BG_SHAPE)
                property = ViewBaseProperty().apply {
                    size[0] = 0
                    size[1] = -1
                    size[2] = 0
                    size[3] = -1
                    solidInt = Color.RED
                    margin[0] = designUnit2px(10)
                    margin[1] = 0
                    margin[2] = designUnit2px(10)
                    margin[3] = 0
                }
            })

            //创建一个水平线性布局
            add(ItemViewData().apply {
                type = ITEM_VIEW_TYPE_LINEAR_H
                property = ViewBaseProperty().apply {
                    size[0] = 0
                    size[1] = -1
                    size[2] = 0
                    size[3] = -1
                }

                treeList = ArrayList<ItemViewData>().apply {
                    //添加 icon
                    add(ItemViewData().apply {
                        viewTag = makeTag(ViewFunCode.ICON)
                        property = ImageViewProperty(ImageViewProperty.ScaleType_CENTER_CROP, ViewFunCode.ICON).apply {
                            size[0] = 0
                            size[2] = 0
                            size[1] = designUnit2px(20)
                            size[3] = designUnit2px(20)
                            layoutGravity = ViewBaseProperty.Gravity_CENTER_VERTICAL
                        }
                    })
                    //添加文字
                    add(ItemViewData().apply {
                        viewTag = makeTag(ViewFunCode.TITLE)
                        property = TextViewProperty(
                            designUnit2px(14).toFloat(),
                            0xFF333333.toInt(),
                            ViewFunCode.TITLE
                        ).apply {
                            size[0] = 1
                            size[2] = 0
                            size[1] = 1
                            size[3] = -2
                            layoutGravity = ViewBaseProperty.Gravity_CENTER_VERTICAL
                        }
                    })
                    //添加文字
                    add(ItemViewData().apply {
                        viewTag = makeTag(ViewFunCode.DESC)
                        property = TextViewProperty(
                            designUnit2px(12).toFloat(),
                            0xFF666666.toInt(),
                            ViewFunCode.DESC
                        ).apply {
                            size[0] = 0
                            size[2] = 0
                            size[1] = -2
                            size[3] = -2
                            layoutGravity = ViewBaseProperty.Gravity_CENTER_VERTICAL
                        }
                    })

                    //添加more icon
                    add(ItemViewData().apply {
                        viewTag = makeTag(ViewFunCode.MORE_ICON)
                        property = ImageViewProperty(
                            ImageViewProperty.ScaleType_CENTER_INSIDE,
                            ViewFunCode.MORE_ICON
                        ).apply {
                            size[0] = 0
                            size[2] = 0
                            size[1] = designUnit2px(12)
                            size[3] = designUnit2px(12)
                            layoutGravity = ViewBaseProperty.Gravity_CENTER_VERTICAL
                        }
                    })
                }
            })
        }
    }
}